package com.ruoyi.tb.lmt.controller;

import java.util.List;
import java.util.Arrays;
import java.util.concurrent.TimeUnit;

import lombok.RequiredArgsConstructor;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.core.validate.QueryGroup;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.tb.lmt.domain.vo.TbEquipmentVo;
import com.ruoyi.tb.lmt.domain.bo.TbEquipmentBo;
import com.ruoyi.tb.lmt.service.ITbEquipmentService;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 总成部件
 *
 * @author ruoyi
 * @date 2023-11-30
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/xha-lmt/equipment")
public class TbEquipmentController extends BaseController {

    private final ITbEquipmentService iTbEquipmentService;

    /**
     * 查询总成部件列表
     */
    @SaCheckPermission("xha-lmt:equipment:list")
    @GetMapping("/list")
    public TableDataInfo<TbEquipmentVo> list(TbEquipmentBo bo, PageQuery pageQuery) {
        return iTbEquipmentService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出总成部件列表
     */
    @SaCheckPermission("xha-lmt:equipment:export")
    @Log(title = "总成部件", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(TbEquipmentBo bo, HttpServletResponse response) {
        List<TbEquipmentVo> list = iTbEquipmentService.queryList(bo);
        ExcelUtil.exportExcel(list, "总成部件", TbEquipmentVo.class, response);
    }

    /**
     * 获取总成部件详细信息
     *
     * @param ID 主键
     */
    @SaCheckPermission("xha-lmt:equipment:query")
    @GetMapping("/{ID}")
    public R<TbEquipmentVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long ID) {
        return R.ok(iTbEquipmentService.queryById(ID));
    }

    /**
     * 新增总成部件
     */
    @SaCheckPermission("xha-lmt:equipment:add")
    @Log(title = "总成部件", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody TbEquipmentBo bo) {
        return toAjax(iTbEquipmentService.insertByBo(bo));
    }

    /**
     * 修改总成部件
     */
    @SaCheckPermission("xha-lmt:equipment:edit")
    @Log(title = "总成部件", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody TbEquipmentBo bo) {
        return toAjax(iTbEquipmentService.updateByBo(bo));
    }

    /**
     * 删除总成部件
     *
     * @param IDs 主键串
     */
    @SaCheckPermission("xha-lmt:equipment:remove")
    @Log(title = "总成部件", businessType = BusinessType.DELETE)
    @DeleteMapping("/{IDs}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] IDs) {
        return toAjax(iTbEquipmentService.deleteWithValidByIds(Arrays.asList(IDs), true));
    }
}
